static cairo_surface_t *surface = NULL;
/* Create a new surface of the appropriate size to store our scribbles */
-static gboolean
-scribble_configure_event (GtkWidget *widget,
- GdkEventConfigure *event,
- gpointer data)
+static void
+create_surface (GtkWidget *widget)
{
GtkAllocation allocation;
cairo_t *cr;
cairo_surface_destroy (surface);
gtk_widget_get_allocation (widget, &allocation);
- surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget),
- CAIRO_CONTENT_COLOR,
- allocation.width,
- allocation.height);
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ allocation.width,
+ allocation.height);
/* Initialize the surface to white */
cr = cairo_create (surface);
cairo_paint (cr);
cairo_destroy (cr);
+}
- /* We've handled the configure event, no need for further processing. */
- return TRUE;
+static void
+scribble_size_allocate (GtkWidget *widget)
+{
+ create_surface (widget);
}
/* Redraw the screen from the surface */
GdkRectangle update_rect;
cairo_t *cr;
+ if (surface == NULL ||
+ cairo_image_surface_get_width (surface) != gtk_widget_get_allocated_width (widget) ||
+ cairo_image_surface_get_height (surface) != gtk_widget_get_allocated_height (widget))
+ create_surface (widget);
+
update_rect.x = x - 3;
update_rect.y = y - 3;
update_rect.width = 6;
cairo_destroy (cr);
- /* Now invalidate the affected region of the drawing area. */
- gdk_window_invalidate_rect (gtk_widget_get_window (widget),
- &update_rect,
- FALSE);
+ gtk_widget_queue_draw_area (widget, update_rect.x, update_rect.y, update_rect.width, update_rect.height);
}
static gboolean
double x, y;
guint button;
- if (surface == NULL)
- return FALSE; /* paranoia check, in case we haven't gotten a configure event */
-
gdk_event_get_button ((GdkEvent *)event, &button);
gdk_event_get_coords ((GdkEvent *)event, &x, &y);
GdkEventMotion *event,
gpointer data)
{
- int x, y;
+ double x, y;
GdkModifierType state;
- if (surface == NULL)
- return FALSE; /* paranoia check, in case we haven't gotten a configure event */
-
- /* This call is very important; it requests the next motion event.
- * If you don't call gdk_window_get_pointer() you'll only get
- * a single motion event. The reason is that we specified
- * GDK_POINTER_MOTION_HINT_MASK to gtk_widget_set_events().
- * If we hadn't specified that, we could just use event->x, event->y
- * as the pointer location. But we'd also get deluged in events.
- * By requesting the next event as we handle the current one,
- * we avoid getting a huge number of events faster than we
- * can cope.
- */
-
- gdk_window_get_device_position (gdk_event_get_window ((GdkEvent *) event),
- gdk_event_get_device ((GdkEvent *) event),
- &x, &y, &state);
+ gdk_event_get_state ((GdkEvent *)event, &state);
+ gdk_event_get_coords ((GdkEvent *)event, &x, &y);
if (state & GDK_BUTTON1_MASK)
draw_brush (widget, x, y);
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
+ gtk_widget_set_vexpand (frame, TRUE);
gtk_box_pack_start (GTK_BOX (vbox), frame);
da = gtk_drawing_area_new ();
gtk_box_pack_start (GTK_BOX (vbox), label);
frame = gtk_frame_new (NULL);
+ gtk_widget_set_vexpand (frame, TRUE);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_box_pack_start (GTK_BOX (vbox), frame);
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (da), scribble_draw, NULL, NULL);
gtk_container_add (GTK_CONTAINER (frame), da);
- /* Signals used to handle backing surface */
-
- g_signal_connect (da,"configure-event",
- G_CALLBACK (scribble_configure_event), NULL);
+ g_signal_connect (da, "size-allocate",
+ G_CALLBACK (scribble_size_allocate), NULL);
/* Event signals */
-
g_signal_connect (da, "motion-notify-event",
G_CALLBACK (scribble_motion_notify_event), NULL);
g_signal_connect (da, "button-press-event",